#!/bin/bash
# deobfuscation
cd deob
python deob.py test $1
# feature extraction
cd /space/Scalable-Malware-Detection
sudo /space/Scalable-Malware-Detection/runExtractor.sh '/space/webcrawl-malware/data/JSTest/' '/space/test'
rm -r /space/webcrawl-malware/data/JSTest/*
# generate feature vector
cd /space/webcrawl-malware/src/model/
sudo python featureVector.py

# modeling and classification
SFILE="/space/outputlogsTerry1000B1000M/ARFF_scaleHist_10_0.0001.csv-100-S.mat"
VFILE="/space/outputlogsTerry1000B1000M/ARFF_scaleHist_10_0.0001.csv-100-V.mat"
FEATUREFILE="/space/test/FeatureVector.csv"

SVDSCRIPT="/home/yacin/tivo-classifier/svd/svd.py"
RCLASSIFY="/home/yacin/tivo-classifier/classify.R"

if [[ $# -ne 1 ]]; then
    echo "usage: ./test.sh features.csv"
    echo "output will be in features.csv.svd.preds"
    exit 2
fi

sudo python $SVDSCRIPT $FEATUREFILE $SFILE $VFILE > $FEATUREFILE.svd

echo "SVD complete"
R < $RCLASSIFY  --vanilla --args $FEATUREFILE.svd >/dev/null
echo "Classification complete. See $1.svd.preds"

# rm /space/test/*
echo 'Classification Result: (1 means Benign, 0 means Malicious)'
cat /space/test/FeatureVector.csv.svd.preds | awk -F"," '{ print $NF }'

